import csv
#job,attack,defense,agile,crit_rate,crit_damage
import random


def set_player(player):
    #1、读取csv文件
    with open("player.csv","r",encoding="utf-8") as f:
        reader = csv.DictReader(f)
        for row in reader:
            if row["job"]==player.job:
                player.attack = int(row["attack"])
                player.defense = int(row["defense"])
                player.agile = int(row["agile"])
                player.crit_rate = int(row["crit_rate"])
                player.crit_damage = int(row["crit_damage"])
                player.weapon = row["weapon"]

    #2、根据player的job设置属性
def set_enemy(enemy):
    #1、读取csv文件
    with open("enemy.csv","r",encoding="utf-8") as f:
        reader = csv.DictReader(f)
        for row in reader:
            if row["type"]==enemy.type:
                enemy.attack = int(row["attack"])
                enemy.defense = int(row["defense"])
                enemy.agile = int(row["agile"])
                enemy.crit_rate = int(row["crit_rate"])
                enemy.crit_damage = int(row["crit_damage"])
                enemy.life = int(row["life"])
                enemy.get_exp = int(row["exp"])

def get_upgrade_exp(level):
    return (level-1)*120 +100

def check_rate(rate):
    if(random.randint(1,100)<=rate):
        return True
    return False
